/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.eclipselabs.damos.dml.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipselabs.damos.dml.DMLPackage;
import org.eclipselabs.damos.dml.FixedPointDataType;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Fixed Point Data Type</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.eclipselabs.damos.dml.impl.FixedPointDataTypeImpl#isSigned <em>Signed</em>}</li>
 *   <li>{@link org.eclipselabs.damos.dml.impl.FixedPointDataTypeImpl#getIntegerLength <em>Integer Length</em>}</li>
 *   <li>{@link org.eclipselabs.damos.dml.impl.FixedPointDataTypeImpl#getFractionalLength <em>Fractional Length</em>}</li>
 *   <li>{@link org.eclipselabs.damos.dml.impl.FixedPointDataTypeImpl#getWordLength <em>Word Length</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class FixedPointDataTypeImpl extends DataTypeImpl implements FixedPointDataType {
	/**
	 * The default value of the '{@link #isSigned() <em>Signed</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isSigned()
	 * @generated
	 * @ordered
	 */
	protected static final boolean SIGNED_EDEFAULT = true;

	/**
	 * The cached value of the '{@link #isSigned() <em>Signed</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isSigned()
	 * @generated
	 * @ordered
	 */
	protected boolean signed = SIGNED_EDEFAULT;

	/**
	 * The default value of the '{@link #getIntegerLength() <em>Integer Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIntegerLength()
	 * @generated
	 * @ordered
	 */
	protected static final int INTEGER_LENGTH_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getIntegerLength() <em>Integer Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIntegerLength()
	 * @generated
	 * @ordered
	 */
	protected int integerLength = INTEGER_LENGTH_EDEFAULT;

	/**
	 * The default value of the '{@link #getFractionalLength() <em>Fractional Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFractionalLength()
	 * @generated
	 * @ordered
	 */
	protected static final int FRACTIONAL_LENGTH_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getFractionalLength() <em>Fractional Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFractionalLength()
	 * @generated
	 * @ordered
	 */
	protected int fractionalLength = FRACTIONAL_LENGTH_EDEFAULT;

	/**
	 * The default value of the '{@link #getWordLength() <em>Word Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getWordLength()
	 * @generated
	 * @ordered
	 */
	protected static final int WORD_LENGTH_EDEFAULT = 0;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected FixedPointDataTypeImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return DMLPackage.Literals.FIXED_POINT_DATA_TYPE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isSigned() {
		return signed;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSigned(boolean newSigned) {
		boolean oldSigned = signed;
		signed = newSigned;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DMLPackage.FIXED_POINT_DATA_TYPE__SIGNED, oldSigned, signed));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getIntegerLength() {
		return integerLength;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIntegerLength(int newIntegerLength) {
		int oldIntegerLength = integerLength;
		integerLength = newIntegerLength;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DMLPackage.FIXED_POINT_DATA_TYPE__INTEGER_LENGTH, oldIntegerLength, integerLength));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getFractionalLength() {
		return fractionalLength;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFractionalLength(int newFractionalLength) {
		int oldFractionalLength = fractionalLength;
		fractionalLength = newFractionalLength;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DMLPackage.FIXED_POINT_DATA_TYPE__FRACTIONAL_LENGTH, oldFractionalLength, fractionalLength));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public int getWordLength() {
		return getIntegerLength() + getFractionalLength();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case DMLPackage.FIXED_POINT_DATA_TYPE__SIGNED:
				return isSigned();
			case DMLPackage.FIXED_POINT_DATA_TYPE__INTEGER_LENGTH:
				return getIntegerLength();
			case DMLPackage.FIXED_POINT_DATA_TYPE__FRACTIONAL_LENGTH:
				return getFractionalLength();
			case DMLPackage.FIXED_POINT_DATA_TYPE__WORD_LENGTH:
				return getWordLength();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case DMLPackage.FIXED_POINT_DATA_TYPE__SIGNED:
				setSigned((Boolean)newValue);
				return;
			case DMLPackage.FIXED_POINT_DATA_TYPE__INTEGER_LENGTH:
				setIntegerLength((Integer)newValue);
				return;
			case DMLPackage.FIXED_POINT_DATA_TYPE__FRACTIONAL_LENGTH:
				setFractionalLength((Integer)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case DMLPackage.FIXED_POINT_DATA_TYPE__SIGNED:
				setSigned(SIGNED_EDEFAULT);
				return;
			case DMLPackage.FIXED_POINT_DATA_TYPE__INTEGER_LENGTH:
				setIntegerLength(INTEGER_LENGTH_EDEFAULT);
				return;
			case DMLPackage.FIXED_POINT_DATA_TYPE__FRACTIONAL_LENGTH:
				setFractionalLength(FRACTIONAL_LENGTH_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case DMLPackage.FIXED_POINT_DATA_TYPE__SIGNED:
				return signed != SIGNED_EDEFAULT;
			case DMLPackage.FIXED_POINT_DATA_TYPE__INTEGER_LENGTH:
				return integerLength != INTEGER_LENGTH_EDEFAULT;
			case DMLPackage.FIXED_POINT_DATA_TYPE__FRACTIONAL_LENGTH:
				return fractionalLength != FRACTIONAL_LENGTH_EDEFAULT;
			case DMLPackage.FIXED_POINT_DATA_TYPE__WORD_LENGTH:
				return getWordLength() != WORD_LENGTH_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (signed: ");
		result.append(signed);
		result.append(", integerLength: ");
		result.append(integerLength);
		result.append(", fractionalLength: ");
		result.append(fractionalLength);
		result.append(')');
		return result.toString();
	}

} //FixedPointDataTypeImpl
